package com.btpj.module_main.adapter

import com.btpj.module_main.R
import com.btpj.module_main.data.entity.NavItem
import com.btpj.module_main.databinding.ListItemNavItemBinding
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder

class NavItemAdapter :
    BaseQuickAdapter<NavItem, BaseDataBindingHolder<ListItemNavItemBinding>>(
        layoutResId = R.layout.list_item_nav_item
    ) {

    var selectItemPosition = 0
        set(value) {
            if (field != value) {
                field = value
                notifyDataSetChanged()
            }
        }

    override fun convert(
        holder: BaseDataBindingHolder<ListItemNavItemBinding>,
        item: NavItem
    ) {
        val binding = holder.dataBinding
        if (binding != null) {
            binding.navItem = item
            binding.isSelected = holder.adapterPosition == selectItemPosition
            binding.executePendingBindings()
        }
    }
}